package com.zp.base.controller.labMaintenance;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.labMaintenance.bo.LabTypeBo;
import com.zp.base.entity.labMaintenance.vo.LabTypeVo;
import com.zp.base.service.labMaintenance.ILabTypeService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 检验项目类型lab_type控制器
 * 前端访问路由地址为:/base/labType
 *
 * @author zhang peng
 * @ date 2023-05-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/labType")
public class LabTypeController extends BaseController {

    private final ILabTypeService iLabTypeService;

    /**
     * 查询检验项目类型lab_type列表 (分页)
     */
    @SaCheckPermission("base:labType:list")
    @GetMapping("/selectPage")
    public TableDataInfo<LabTypeVo> selectPage (LabTypeBo bo, PageQuery pageQuery) {
        return iLabTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询检验项目类型lab_type列表 (不分页)
     */
    @SaCheckPermission("base:labType:list")
    @GetMapping("/list")
    public R<List<LabTypeVo>> list (LabTypeBo bo) {
        List<LabTypeVo> list = iLabTypeService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出检验项目类型lab_type列表
     */
    @SaCheckPermission("base:labType:export")
    @Log(title = "检验项目类型lab_type", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (LabTypeBo bo, HttpServletResponse response) {
        List<LabTypeVo> list = iLabTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "检验项目类型lab_type", LabTypeVo.class, response);
    }

    /**
     * 获取检验项目类型lab_type详细信息
     *
     * @param labTypeId 主键
     */
    @SaCheckPermission("base:labType:list")
    @GetMapping("/{labTypeId}")
    public R<LabTypeVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String labTypeId) {
        return R.ok(iLabTypeService.queryById(labTypeId));
    }

    /**
     * 新增检验项目类型lab_type
     */
    @SaCheckPermission("base:labType:add")
    @Log(title = "检验项目类型lab_type", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody LabTypeBo bo) {
        return toAjax(iLabTypeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改检验项目类型lab_type
     */
    @SaCheckPermission("base:labType:edit")
    @Log(title = "检验项目类型lab_type", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody LabTypeBo bo) {
        return toAjax(iLabTypeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除检验项目类型lab_type
     *
     * @param labTypeIds 主键串
     */
    @SaCheckPermission("base:labType:remove")
    @Log(title = "检验项目类型lab_type", businessType = BusinessType.DELETE)
    @DeleteMapping("/{labTypeIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] labTypeIds) {
        return toAjax(iLabTypeService.deleteWithValidByIds(Arrays.asList(labTypeIds), true) ? 1 : 0);
    }
}
